package com.by.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author wang
 * @version 版本号 ${}
 * @className configSwaggerConfig
 * @日期 2024/9/5 11:06
 * @since jdk1.8
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {
    
    @Bean
    public Docket createRestApi(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .enable(true) //配置是否启用Swagger，如果是false，在浏览器将无法访问
                .select()// 通过.select()方法，去配置扫描接口,RequestHandlerSelectors配置如何扫描接口
                .apis(RequestHandlerSelectors.basePackage("com.by.controller"))//控制类所在的包
                .paths(PathSelectors.ant("/v1/**"))// 配置如何通过path过滤,即这里只扫描请求以/v1开头的路径
                .build();
    }
    
    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("微商分销系统")
                .description("这是微商分销系统后台接口文档,实时更新，请及时关注接口变化！")
                .version("v1.0")
                .contact(new Contact("www", "http://localhost", "1716201345@qq.com"))
                .build();
    }
}
